Package aspose.cells

Source Code of aspose.cells.AsposeCreateCharts

package aspose.cells;

import com.aspose.cells.Cell;
import com.aspose.cells.Cells;
import com.aspose.cells.Chart;
import com.aspose.cells.ChartCollection;
import com.aspose.cells.ChartType;
import com.aspose.cells.SeriesCollection;
import com.aspose.cells.Workbook;
import com.aspose.cells.Worksheet;
import com.aspose.cells.WorksheetCollection;

public class AsposeCreateCharts
{
  public static void main(String[] args) throws Exception
  {
      // Instantiating a Workbook object
        Workbook workbook = new Workbook();

        // Obtaining the reference of the first worksheet
        WorksheetCollection worksheets = workbook.getWorksheets();
        Worksheet sheet = worksheets.get(0);

        // Adding some sample value to cells
        Cells cells = sheet.getCells();
        Cell cell = cells.get("A1");
        cell.setValue(50);
        cell = cells.get("A2");
        cell. setValue (100);
        cell = cells.get("A3");
        cell.setValue(150);
        cell = cells.get("B1");
        cell.setValue(4);
        cell = cells.get("B2");
        cell.setValue(20);
        cell = cells.get("B3");
        cell.setValue(50);

        ChartCollection charts = sheet.getCharts();

        // Adding a chart to the worksheet
        int chartIndex = charts.add(ChartType.PYRAMID,5,0,15,5);
        Chart chart = charts.get(chartIndex);

        // Adding NSeries (chart data source) to the chart ranging from "A1" cell to "B3"
        SeriesCollection serieses = chart.getNSeries();
        serieses.add("A1:B3", true);

        // Saving the Excel file
        workbook.save("data/AsposeChart.xls");
       
        // Print message
        System.out.println("Workbook with chart is successfully created.");
  }
}
TOP

Related Classes of aspose.cells.AsposeCreateCharts

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.